#include "TankShell.h"
#include "Utility.h"
#include "Resources.h"

LINKCLASSTONAME("ent_shell", TankShell);

TankShell::TankShell(sf::RenderWindow *App) : BaseMoveable(App)
{
	DrawOrder = 2;
	sf::Vector2f Points[3];
	Points[0] = sf::Vector2f(0,2);
	Points[1] = sf::Vector2f(2,2);
	Points[2] = sf::Vector2f(-2,-2);
	CreatePhysics();

	PhysicsObject* p = GetPhysicsObject();
	p->PhysicsInitPolygon(this, Points, 3);
	p->SetMass(2);
	p->SetLinearDamping(0.f);
	p->SetAngularDamping(0.f);

	Shape = sf::Shape::Circle(0, 0, 4, sf::Color::Black);
	KillTime = GameGlobals::Instance()->CurTime + 1.5f;
}

TankShell::~TankShell(void)
{

}

bool TankShell::ShouldCollide(BaseMoveable *other)
{
	if (GetOwner() != NULL)
	{
		if (other->GetClass() == GetOwner()->GetClass())
		{
			return false;
		}
	}
	if (other->GetClass() == GetClass())
	{
		return false;
	}
	return true;
}

void TankShell::OnCollide(BaseMoveable *ent1, BaseMoveable *ent2, CollisionData CollideInfo)
{
	ent2->OnTakeDamage(this, Util::Random(15.f,35.f));
	Delete();
}

void TankShell::SetSize(int Size)
{
	Shape = sf::Shape::Circle(GetPos().x, GetPos().y, Size, sf::Color::Black);
}

void TankShell::Think()
{
	if (KillTime < GameGlobals::Instance()->CurTime)
	{
		Delete();
	}
}

void TankShell::Draw()
{
	Shape.SetPosition(GetSFMLPos());
	pRender->Draw(Shape);
}